package com.wang.music.controller;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.wang.music.constant.HttpStatusEnum;
import com.wang.music.entity.Admin;
import com.wang.music.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author zifan
 * @since 2021-03-03
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    public Map<String,Object> login(Admin admin){
        HashMap<String, Object> resMap = new HashMap<>();
        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Admin::getName,admin.getName());
        wrapper.lambda().eq(Admin::getPassword,admin.getPassword());
        Admin resAdmin = adminService.getOne(wrapper);
        System.out.println("resAdmin = " + resAdmin);
        if (ObjectUtil.isNull(resAdmin)){
            //用户名或密码错误
            resMap.put("status",HttpStatusEnum.FAILURE.getStatus());
            resMap.put("msg",HttpStatusEnum.FAILURE.getMsg());
        }else {
            resMap.put("status",HttpStatusEnum.SUCCESS.getStatus());
            resMap.put("msg",HttpStatusEnum.SUCCESS.getMsg());
        }
        return resMap;
    };
}

